home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.02 Feb 90 / Mouse Source / TrackLock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-22  |  1.9 KB  |  80 lines  |  [TEXT/KAHL]

  1. /*                                            TrackLock.c                                            */
  2. /*
  3.  * Copyright © 1989 Martin Minow. All rights reserved.
  4.  *
  5.  * _Track_lock(track_handle, &state)
  6.  * TrackHandle    track_handle;
  7.  *
  8.  * _Track_unlock(&state)
  9.  *
  10.  * _Track_lock() is called at the beginning of all
  11.  * functions to lock the TrackHandle in memory, save
  12.  * the old port, clip region and text parameters; and
  13.  * and set our port, clipRect, and text parameters.
  14.  *
  15.  * _Track_unlock() is called at the end to restore
  16.  * the original parameters.
  17.  */
  18.  
  19. #include "TrackEdit.h"        
  20. #define TR    (*tr)
  21.  
  22. /*
  23.  * _Track_lock is called at the start of all
  24.  * user-callable functions to lock the TrackRecord
  25.  * in memory.  It returns a pointer to the record.
  26.  */
  27. TrackPtr
  28. _Track_lock(track_handle, sp)
  29. TrackHandle                        track_handle;
  30. register _Track_state    *sp;
  31. {
  32.         register TrackPtr        tr;
  33.         
  34.         sp->track_handle = track_handle;
  35.         sp->oldHState = HGetState(track_handle);
  36.         MoveHHi(track_handle);
  37.         HLock(track_handle);
  38.         tr = (*track_handle);
  39.         GetPort(&sp->oldPort);
  40.         SetPort(TR.inPort);
  41.         /*
  42.          * Save the old clip region and set the clip region to
  43.          * the intersection of the old region and the viewRect.
  44.          */
  45.         sp->oldClip = NewRgn();
  46.         GetClip(sp->oldClip);
  47.         ClipRect(&TR.viewRect);
  48.         SectRgn(
  49.             sp->oldClip, thePort->clipRgn, thePort->clipRgn);
  50.         /*
  51.          * Save the old drawing parameters.
  52.          * (Perhaps even color?)
  53.          */
  54.         sp->oldFont = thePort->txFont;    TextFont(TR.txFont);
  55.         sp->oldFace = thePort->txFace;    TextFace(TR.txFace);
  56.         sp->oldMode = thePort->txMode;    TextMode(TR.txMode);
  57.         sp->oldSize = thePort->txSize; TextSize(TR.txSize);
  58.         return (tr);
  59. }
  60.  
  61. /*
  62.  * _Track_unlock()
  63.  * Restore the track handle to the state it had on
  64.  * entrance.
  65.  */
  66. void
  67. _Track_unlock(sp)
  68. register _Track_state    *sp;
  69. {
  70.         TextSize(sp->oldSize);
  71.         TextMode(sp->oldMode);
  72.         TextFace(sp->oldFace);
  73.         TextFont(sp->oldFont);
  74.         SetClip(sp->oldClip);
  75.         DisposeRgn(sp->oldClip);
  76.         SetPort(sp->oldPort);
  77.         HSetState(sp->track_handle, sp->oldHState);
  78. }
  79.  
  80.